package com.newcapec.erp.ui;


import com.newcapec.erp.bean.LoginEntity;
import com.newcapec.erp.main.LoginManager;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginUI extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	JPanel p;
	/**
	 * Create the frame.
	 */
	public LoginUI() {
		setIconImage(Toolkit.getDefaultToolkit().getImage("image/logo.png"));
		setTitle("登录界面\r\n");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(1112,570);
		contentPane = new JPanel(){
			public void  paintComponent(Graphics g){
				super.paintComponent(g);
				ImageIcon ii=new ImageIcon("images/bac.png");
				g.drawImage(ii.getImage(),0,0,getWidth(),getHeight(),ii.getImageObserver());
			}
		};
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel labelTitle = new JLabel("ERP 管 理 系 统");
		labelTitle.setHorizontalAlignment(SwingConstants.RIGHT);
		labelTitle.setFont(new Font("微软雅黑", Font.BOLD, 30));
		labelTitle.setForeground(Color.WHITE);
		labelTitle.setBounds(320, 120, 300, 30);
		contentPane.add(labelTitle);

		JLabel lblNewLabel = new JLabel("用户名：");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setBounds(372, 190, 92, 25);
		contentPane.add(lblNewLabel);

		textField = new JTextField();
		textField.setBounds(474, 190, 160, 34);
		contentPane.add(textField);
		textField.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("密  码：");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		lblNewLabel_1.setForeground(Color.WHITE);
		lblNewLabel_1.setBounds(372, 255, 92, 27);
		contentPane.add(lblNewLabel_1);

		passwordField = new JPasswordField();
		passwordField.setBounds(474, 255, 160, 38);
		contentPane.add(passwordField);

		JButton btnNewButton = new JButton("登录");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String userName=textField.getText();
				String userPwd=new String(passwordField.getPassword());
				LoginEntity loginEntity=new LoginEntity(userName,userPwd);
				LoginManager loginManager=new LoginManager();
				loginManager.chkLogin(loginEntity);
				dispose();
			}
		});
		btnNewButton.setBounds(474, 310, 160, 34);
		contentPane.add(btnNewButton);
		setLocationRelativeTo(null);
		setVisible(true);
	}

}
